package com.nhjf.dao.teachers;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.teachers.OperationLog;
import com.nhjf.pojo.qo.teachers.OperationLogQo;
@Repository
public class OperationLogDao extends BaseDao<OperationLog, OperationLogQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, OperationLogQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {
			criteria.setFetchMode("userId", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(StringUtils.isNotBlank(qo.getOperationDescription())) {
				criteria.add(Restrictions.eq("operationDescription",qo.getOperationDescription()));
			}
			if(qo.getOperationLogid()!=null) {
				criteria.add(Restrictions.eq("operationLogid",qo.getOperationLogid()));
			}
			if(StringUtils.isNotBlank(qo.getOperationUserName())) {
				criteria.add(Restrictions.eq("operationUserName",qo.getOperationUserName()));
			}
			if(qo.getOperationTime()!=null) {
				criteria.add(Restrictions.eq("operationTime",qo.getOperationTime()));
			}
			if(qo.getOperationType()!=null) {
				criteria.add(Restrictions.eq("operationType",qo.getOperationType()));
			}
			if(qo.getUserId()!=null) {
				criteria.setFetchMode("userId",FetchMode.SELECT);
				criteria.add(Restrictions.eq("userId.id",qo.getUserId()));
			}
		}
		
		return criteria;
	}

	@Override
	protected Class<OperationLog> getEntityClass() {
		// TODO Auto-generated method stub
		return OperationLog.class;
	}

}
